<?php
class categoryController extends siteController
{
    public function index()
    {
        $cid = intval($_GET['cid']);
        if (empty($cid)) {
            $this->error404();
        }

        $this->info=model('special_class')->info($cid);
        if (!is_array($this->info)){
            $this->error404();
        }

        //位置导航
        $this->nav=model('special_class')->nav($cid);
        //超链接

        //设置分页
        $size = intval($this->info['page']); 
        if (empty($size)) {
            $listrows = 10;
        } else {
            $listrows = $size;
        }
        $url=url('category/index',array('cid'=>$cid,'page'=>'{page}'));
        $limit=$this->pageLimit($url,$listrows);

        //设置专题属性
        if ($this->info['type'] == 0) {
            $son_id = model('special_class')->getcat($cid);
            $where = 'AND B.status=1 AND A.cid in (' . $son_id . ')';
        } else {
            $where = 'AND B.status=1 AND A.cid=' . $this->info['cid'];
        }

        //执行查询列表
        $loop=model('special_list')->special_list($limit,$where,$this->info['content_order'].',');
        $count = model('special_list')->special_count($where);
        if(!empty($loop)){
            $i=0;
            foreach ($loop as $key=>$value) {
                $i++;
                $list[$key]=$value;
                $list[$key]['aurl']=api('content','content_aurl',$value);
                $list[$key]['i']=$i;
            }
        }
        $this->loop=$list;
        //获取分页
        $this->page=$this->pageShow($count);
        $this->count=$count;
        //查询上级专题信息
        $this->parent_category = model('special_class')->info($this->info['pid']);
        //获取顶级专题信息
        $this->top_category = model('special_class')->info($this->nav[0]['cid']);
        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>$this->info['name'],'keywords'=>$this->info['keywords'],'description'=>$this->info['description']));
        
        $this->show($this->info['class_tpl']);
    }

}
